package com.woniuxy.controller;

import com.woniuxy.entity.LoginEntity;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.LoginAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 马宇航
 * @Do: 用于用户登录
 * @DateTime: 22/05/23/0023 上午 10:30
 * @Component: 成都蜗牛学苑
 **/
@RestController
@CrossOrigin
public class LoginAuthController {

    LoginAuthService loginAuthService;
    //推荐用法，在构造方法来进行自动注入
    @Autowired
    public LoginAuthController(LoginAuthService loginAuthService) {
        this.loginAuthService = loginAuthService;
    }

    @RequestMapping("/login")
    public ResponseEntity login(@RequestBody LoginEntity loginEntity){
      return loginAuthService.login(loginEntity.getUsername(),loginEntity.getPassword());
    }
    @RequestMapping("/401")
    public ResponseEntity response401(){
        return new ResponseEntity(401,"认证失败",null);
    }
}
